package com.jfs.qy.config.component;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Description 存放告警事件阻塞队列
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/11/4
 */
public class AlarmEventBlockQueue {
    private final static BlockingQueue<AlarmEvent> BLOCKING_QUEUE =new LinkedBlockingDeque<>();

    /**
     * 放入事件到队列中
     * @param alarmEvent
     */
    public static void put(AlarmEvent alarmEvent){
        try {
            BLOCKING_QUEUE.put(alarmEvent);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    public static AlarmEvent get(){
        try {
            if (!BLOCKING_QUEUE.isEmpty()){
                return BLOCKING_QUEUE.take();
            }
            return null;
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
